import java.util.Scanner;

public class Test13 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        String t = scanner.next();

        int maxK = 0;
        for (int i = 1; i <= n; i++) {
            if(n % 1 == 0){
                maxK = Math.max(maxK , canPart(t,i));
            }
        }
        System.out.println(maxK);
    }

    private static int canPart(String t ,int k){
        int n = t.length();
        int[] count = new int[10];
        for (int i = 0; i < n; i++) {
            count[t.charAt(i) - '0']++;
        }
        for (int i = 0; i < k; i++) {
            int[] tmp = new int[10];
            for (int j = i; j < n; j+=k) {
                tmp[t.charAt(j) - '0']++;
            }
            boolean flag = true;
            for (int c = 0; c < 10; c++) {
                if(tmp[c] * k != count[c]){
                    flag = false;
                    break;
                }
            }
            if(!flag){
                return 0;
            }
        }
        return k;
    }
}
